// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueI18n from 'vue-i18n'
import Api from './Api' // 导入api接口

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
// import zhtwLocale from 'element-ui/lib/locale/lang/zh-tw'
// import ru from 'element-ui/lib/locale/lang/ru'
import cookies from 'vue-cookies'

// 公共样式库
import '../static/css/common.css'
import errorText from '../static/errorText'
import loading from './JS/loading.js' // 引入loading
import Toast from './Js/Toast.js' // Message

// swiper
import 'swiper/dist/css/swiper.min.css'
import 'swiper/dist/js/swiper.min'
// 注册全局过滤器
import * as filters from './Js/filters'
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
// Vue.use(ElementUI)
Vue.prototype.$EventBus = new Vue()
Vue.prototype.$Api = Api // 将api挂载到vue的原型上

Vue.use(VueI18n)
Vue.use(loading)
Vue.use(Toast)
Vue.use(cookies)

const i18n = new VueI18n({
  locale: localStorage.getItem('language') || 'zh-cn',
  messages: {
    // 'zh': require('./lang/zh'),
    // 'en': require('./lang/en')
    'en': Object.assign(require('./lang/en'), enLocale), // 将我们项目中的语言包与Element的语言包进行合并
    'zh-cn': Object.assign(require('./lang/zh-cn'), zhLocale),
    'zh-tw': Object.assign(require('./lang/zh-tw')),
    'ru': Object.assign(require('./lang/ru'))
  }
})
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.prototype.errorText = errorText

/* eslint-disable no-new */
new Vue({
  el: '#app',
  i18n,
  router,
  components: { App },
  template: '<App/>'
})
